package com.atguigu.service.impl;

import com.atguigu.mapper.ArticleMapper;
import com.atguigu.pojo.Article;
import com.atguigu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program:weiblog-server
 * @author: 马雨清
 * @Time: 2023/8/21  11:13
 * @description:
 */
@Service
@Transactional
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    @Transactional(readOnly = true)
    public List<Article> findArticle(Article article) {
        List<Article> articleList = articleMapper.selectAllArticle(article);
        return articleList;
    }

    @Override
    @Transactional(readOnly = true)
    public List<Article> findArticleByUid(Integer uid) {
        List<Article> articleList = articleMapper.selectArticleByUid(uid);
        return articleList;
    }

    @Override
    @Transactional(readOnly = true)
    public Article findArticleById(Integer id) {
        return articleMapper.selectArticleById(id);
    }

    @Override
    public Integer updateArticle(Article article) {
        Integer result = articleMapper.updateArticle(article);
        return result;
    }

    @Override
    public Integer addArticle(Article article) {
        Integer result = articleMapper.insertArticle(article);
        return result;
    }

    @Override
    public Integer deleteArticleById(Integer id) {
        Integer result = articleMapper.deleteById(id);
        return result;
    }
}
